package com.pioneer.controller.client;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pioneer.common.annotation.Log;
import com.pioneer.common.core.controller.BaseController;
import com.pioneer.common.core.domain.AjaxResult;
import com.pioneer.common.enums.BusinessType;
import com.pioneer.common.utils.SecurityUtils;
import com.pioneer.web.client.domain.CliAddress;
import com.pioneer.web.manager.domain.ManDeal;
import com.pioneer.web.manager.service.IManDealService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 订单管理
 *
 * @author hlm
 */
@RestController
@RequestMapping("/client/deal")
public class ClientDealController extends BaseController {

    @Resource
    private IManDealService dealService;

    /**
     * 获取订单管理列表
     *
     * @param deal 查询条件
     * @return 结果
     */
    @PreAuthorize("@ss.hasPerm('client:deal:list')")
    @GetMapping("/list")
    public AjaxResult list(ManDeal deal) {

        boolean isPage = startPage();
        deal.setClientId(SecurityUtils.getUserId());
        System.out.println(deal);
        List<ManDeal> list = dealService.dealList1(deal);

        return success(isPage, list);
    }
    /**
     * 根据订单管理id获取详细信息
     *
     * @param dealId 订单管理id
     * @return 结果
     */
    @PreAuthorize("@ss.hasPerm('client:deal:query')")
    @GetMapping(value = "/{dealId}")
    public AjaxResult getInfo(@PathVariable Long dealId) {
        ManDeal manDeal=new ManDeal();
        manDeal.setId(dealId);
        return AjaxResult.success(dealService.dealList(manDeal));
    }

    /**
     * 新增订单管理
     *
     * @param deal 订单管理
     * @return 结果
     */
    @PreAuthorize("@ss.hasPerm('client:deal:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ManDeal deal) {


        return toAjax(dealService.addDeal(deal));
    }

    /**
     * 修改订单管理
     *
     * @param deal 订单管理
     * @return 结果
     */
    @PreAuthorize("@ss.hasPerm('client:deal:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ManDeal deal) {
        return toAjax(dealService.updateById(deal));
    }

    /**
     * 删除订单管理
     *
     * @param dealIds 订单管理id数组
     * @return 结果
     */
    @PreAuthorize("@ss.hasPerm('client:deal:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dealIds}")
    public AjaxResult remove(@PathVariable Long[] dealIds) {
        return toAjax(dealService.removeByIds(Arrays.asList(dealIds)));
    }
}
